package com.gxan.web.controller;

import com.alibaba.fastjson.JSONObject;
import com.gxan.common.JsonResult;
import com.gxan.service.HumanService;
import com.gxan.service.impl.HumanServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/queryHumanList")
public class QueryHumanServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1.获取前端传递的分页字段
        Integer currentPage = Integer.parseInt(request.getParameter("page"));
        Integer pageSize = Integer.parseInt(request.getParameter("limit"));

        //2.调用service完成查询所有所有数据封装到JsonResult（Employee表中的数据和分页数据和code状态码和消息msg）
        //动态数据表格做数据展示到页面，前端需要后端返回一个响应成功的状态码code，值必须是0
        HumanService humanService = new HumanServiceImpl();
        JsonResult jsonResult = humanService.queryHumanList(currentPage, pageSize);
        //3.响应
        response.setContentType("application/json;charset=utf-8");
        response.getWriter().write(JSONObject.toJSONString(jsonResult));
        response.getWriter().flush();
        response.getWriter().close();


    }
}
